#if USE_CONSOLE

#include <omp.h>
#include <QFileInfo>
#include <QImage>
#include <QObject>
#include <QDebug>
#include <QCoreApplication>
#include <iostream>

#include "src/scene/scene.h"
#include "src/interface/image.h"
#include "src/interface/input.h"

int main(int argc, char *argv[]){
    QCoreApplication app(argc, argv);

    omp_set_num_threads(4);

    for(int i = 1; i < argc; i++)
    {
        char *fileName = argv[i];//nome do arquivo que vou ler para fazer o raytracing, tem que estar completo!
    //    char *outputFileName = argv[2];//nome do arquivo que vou salvar a imagem e as informações


        //carregar a cena
        QFile inputFile(QString("./test/input/") + QString(fileName) + QString(".obs"));

        #if DEBUG
        qDebug() << "Arquivo de entrada: "<< QString("./test/input/") + QString(fileName) + QString(".obs") << endl;
        #endif //DEBUG

        Input input;
        Scene scene;
        input.parseScene(&inputFile, &scene);
        //*********

        //setando a imagem que será salva
        Camera *camera = scene.getCamera();
        QImage img(camera->getM(),camera->getN(), QImage::Format_RGB32);
        img.fill(0);

        Image image(&scene, &img);

        QObject::connect(&scene, SIGNAL(setLine(unsigned int, uchar *)), &image, SLOT(updateImageLine(unsigned int, uchar *)));
        //*********

/*
        //rodar raytracing
        #if DEBUG
        qDebug() << "Comecando raytracing" << endl;
        #endif //DEBUG
        scene.doRaytracing();
        // *********


        //salvar
        image.save(QString("./test/output/") + QString(fileName));
*/


////        //rodar photon mapping de verdade
////        scene.doRaytracing();
////
////        //salvar
////        image.save(QString("./test/output/") + QString(fileName) + QString("_RAYTRACING"));
////
////        #if DEBUG
////        qDebug() <<"Salvou em " << QString("./test/output/") + QString(fileName) + QString("_RAYTRACING") << endl;
////        #endif //DEBUG
//
//
//
//        img.fill(0);
        //rodar photon mapping para photons
        scene.doPhotonMapping(true);

        //salvar
        image.save(QString("./test/output/") + QString(fileName) + QString("_PHOTONS"));

        #if DEBUG
        qDebug() <<"Salvou em " << QString("./test/output/") + QString(fileName) + QString("_PHOTONS") << endl << endl;
        #endif //DEBUG




        img.fill(0);
        //rodar photon mapping de verdade
        scene.doPhotonMapping();

        //salvar
        image.save(QString("./test/output/") + QString(fileName));

        #if DEBUG
        qDebug() <<"Salvou em " << QString("./test/output/") + QString(fileName) << endl << endl;
        #endif //DEBUG

        //*********
    }

    return 0;
}


#else


#include <QApplication>

#include "src/interface/window.h"

int main(int argc, char *argv[]){
	QApplication app(argc, argv);
	Window window;
	window.show();
	return app.exec();
}
#endif //USE_INTERFACE
